package com.itheima.pinda.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pinda.DTO.truck.TruckDto;
import com.itheima.pinda.common.utils.PageResponse;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdTruckService;
import com.itheima.pinda.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "车辆管理")
@RestController
@RequestMapping
public class PdTruckController {

    @Autowired
    private PdTruckService truckService;

    @ApiOperation(value = "车辆新增")
    @PostMapping(value = "/insert")
    public TruckDto truckInsert(TruckDto truckDto){

        return truckService.truckInsert(truckDto);
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/id")
    public TruckDto truckSelectById(@RequestParam("id") String id){

        return truckService.truckSelectById(id);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/selectPage")
    public PageResponse truckByPage(@RequestParam("pageNum")Integer pageNum,
                                    @RequestParam("pageSize")Integer pageSize,
                                    @RequestParam(value = "truckTypeId",required = false) String truckTypeId,
                                    @RequestParam(value = "licensePlate",required = false) String licensePlate,
                                    @RequestParam(value = "fleetId",required = false)String fleetId){
        IPage page = truckService.truckByPage(pageNum, pageSize, truckTypeId, licensePlate, fleetId);
        return ResultUtils.pageResult(pageNum,pageSize,page);
    }

    @ApiOperation(value = "批量删除")
    @DeleteMapping(value = "/delete")
    public Result truckDelete(@RequestBody List<String> ids){
        truckService.truckDelete(ids);

        return Result.ok("删除成功！");
    }

}
